package com.rising.face.thread.ThreadLocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class NumUtil {
    private static ThreadLocal<Integer> addNumThreadLocal = new ThreadLocal<Integer>();
    private static ThreadLocal<Integer> addNumThreadLocal2 = new ThreadLocal<Integer>();

    public static int add10(int num) {
        addNumThreadLocal.set(num);
        /*try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        return addNumThreadLocal.get() + 10;
    }

    public static void main(String[] args) {

        ExecutorService service = Executors.newFixedThreadPool(20);

        for (int i = 0; i < 20; i++) {
            int num = i;
            service.execute(()->{
                System.out.println(num + " " +  NumUtil.add10(num));
            });
        }
        service.shutdown();

        addNumThreadLocal.set(100);
        addNumThreadLocal2.set(102);
        System.out.println(addNumThreadLocal.get());
        System.out.println(addNumThreadLocal2.get());
    }
}
